###########################################################################
#
# Copyright (2017), Institute of software, Chinese Academy of Sciences
#
###########################################################################


rm -rf /abcs/$1/temp/
rm -rf /abcs/$1/work/
rm -rf /abcs/$1/logs/

cd /abcs
tar zcvf $1-$2.tar.gz $1-$2/*

mkdir -p /root/rpmbuild/SOURCES
mv $1-$2.tar.gz /root/rpmbuild/SOURCES/

mkdir -p /root/rpmbuild/SPECS
rm -rf /root/rpmbuild/SPECS/$1.spec
echo "Name: $1" > /root/rpmbuild/SPECS/$1.spec
echo "Version: $2" >> /root/rpmbuild/SPECS/$1.spec
echo "Release: abcsys%{?dist}" >> /root/rpmbuild/SPECS/$1.spec
echo "Source: %{name}-%{version}.tar.gz" >> /root/rpmbuild/SPECS/$1.spec
echo "Requires: jdk" >> /root/rpmbuild/SPECS/$1.spec
echo "Summary: abcsys" >> /root/rpmbuild/SPECS/$1.spec
echo "License: ASL 2.0" >> /root/rpmbuild/SPECS/$1.spec
echo "%description" >> /root/rpmbuild/SPECS/$1.spec
echo "abcsys" >> /root/rpmbuild/SPECS/$1.spec
echo "%prep" >> /root/rpmbuild/SPECS/$1.spec
echo "%setup -n %{name}-%{version}" >> /root/rpmbuild/SPECS/$1.spec
echo "%install" >> /root/rpmbuild/SPECS/$1.spec
echo "mkdir -p %{buildroot}/abcs" >> /root/rpmbuild/SPECS/$1.spec
echo "cp -r /root/rpmbuild/BUILD/%{name}-%{version}  %{buildroot}/abcs/" >> /root/rpmbuild/SPECS/$1.spec
echo "%files" >> /root/rpmbuild/SPECS/$1.spec
echo "/abcs" >> /root/rpmbuild/SPECS/$1.spec

rpmbuild -ba /root/rpmbuild/SPECS/$1.spec

mv /root/rpmbuild/RPMS/x86_64/$1-$2-abcsys.el7.centos.x86_64.rpm .
